﻿/*
 * ----------------------------------------------------------------
 * Copyright @ @@神农写代码 2023. All rights reserved.
 
 * 作    者 ：@@神农写代码 
 
 * 创建时间 ：2023/2/3 22:19:59
 
 * CLR 版本 ：4.0.30319.42000
 
 * 命名空间 ：GCNF.Algorithm.Polling
 
 * 类 名 称 ：ARoundRobin

 * 类 描 述 ：
 
 * 博客地址：fu-shi-rong.blog.csdn.net
 
 * ------------------------------------------------------
 * 历史更新记录
 
 * 版本 ：  V1.0.0.0        修改时间：2023/2/3 22:19:59         修改人：
 
 * 修改内容：
 * 
 */
using System;
using System.Collections.Generic;
using System.Text;

namespace GCNF.Algorithm.Polling
{
    public abstract class AbstractRoundRobin
    {
        #region 变量初始化
        protected  List<RoundRobinConfiguration> serviceAddressList = new List<RoundRobinConfiguration>();
        /// <summary>
        /// 选择轮询算法类型
        /// </summary>
        public RoundRobinEnum roundRobinEnum;
        //请求次数计数器
        protected static int requestCount = 0;
        //静态锁
        protected static object _lock = new object();
        //轮询领域
        protected RoundRobinConfiguration robinConfiguration = new RoundRobinConfiguration();
        #endregion

        #region  函数
        /// <summary>
        ///轮询算法
        /// </summary>
        /// <returns></returns>
        public abstract RoundRobinConfiguration Select(List<RoundRobinConfiguration> serviceAddress);

        /// <summary>
        ///分配权重
        /// </summary>
        /// <returns></returns>
        protected void AssignWeight(List<RoundRobinConfiguration> serviceAddress)
        {
            foreach (RoundRobinConfiguration configuration in serviceAddress)
            {
                for (int i = 0; i < configuration.Weight; i++)
                {
                    serviceAddressList.Add(configuration);
                }
            } 
        } 
        #endregion 
    }
}
